package com.chixing.service.impl;

import com.chixing.mapper.FlowMapper;
import com.chixing.mapper.MyorderMapper;
import com.chixing.pojo.Flow;
import com.chixing.pojo.FlowExample;
import com.chixing.pojo.Myorder;
import com.chixing.service.FlowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FlowServiceImpl implements FlowService {
    @Autowired
    private FlowMapper flowMapper;

    @Autowired
    private MyorderMapper myorderMapper;

    @Override
    public boolean save(Flow flow,String orderId) {
        //1. 添加流水
        int rows = flowMapper.insert(flow);
        System.out.println("insert flow rows:" + rows);


        //2. 修改订单状态
        Myorder myorder = myorderMapper.selectByPrimaryKey(orderId);
 //       flow.getOrderId()
        myorder.setOrderStatus(1); // 已支付
        int updateRows = myorderMapper.updateByPrimaryKeySelective(myorder);
        System.out.println("update order status :" + updateRows);
        return true;
    }

    @Override
    public Flow getByOrderNum(String orderNum) {
        FlowExample example = new FlowExample();
        example.createCriteria().andOrderNumEqualTo( orderNum);
        List<Flow> flowList = flowMapper.selectByExample(example);
        if(flowList !=null && flowList.size()>0)
            return flowList.get(0);
        return null;
    }
}
